package cn.micai.base.thread;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * 描述：
 * <p>
 *
 * @author: 赵新国
 * @date: 2018/2/22 15:42
 */
public class SynContainer2 {

    public static void main(String [] args){
        //Map<String,String> map = Collections.synchronizedMap(new HashMap<String,String>());
        Map<String,String> map = new HashMap<String,String>();

        Thread t1 = new Thread(new Runnable() {

            @Override
            public void run() {
                for(int i=0;i<25;i++){
                    map.put(String.valueOf(i), String.valueOf(i));
                }
            }
        },"t1");

        Thread t2 = new Thread(new Runnable() {

            @Override
            public void run() {
                for(int j=25;j<50;j++){
                    map.put(String.valueOf(j), String.valueOf(j));
                }
            }
        },"t2");
        t1.start();
        t2.start();

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        for(int k=0;k<50;k++){
            if(!String.valueOf(k).equals(map.get(String.valueOf(k)))){
                System.out.println(String.valueOf(k)+":"+map.get(String.valueOf(k)));
            }
        }

    }
}
